/**
 * 
 */
package com.pactera.android.activity;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.pactera.android.R;
import com.pactera.android.util.Constants;
import com.pactera.android.util.HttpUtil;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author David Zheng
 *
 */
public class FeedbackActivity extends BaseActivity {
	
	static final String TAG = "FeedbackActivity";
	
	private TextView headerText;
	
	private EditText content;
	
	private Button backBtn;
	
	private Button submitBtn;

	/* (non-Javadoc)
	 * @see com.pactera.android.activity.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.feedback_activity);
		initHeader();
	}
	
	private void initHeader() {
		headerText = (TextView)findViewById(R.id.topTextId);
		headerText.setText(R.string.feedback);
		backBtn = (Button)findViewById(R.id.backBtnId);
		backBtn.setVisibility(0);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();			
			}			
		});
		
		submitBtn = (Button)findViewById(R.id.settingBtnId);
		submitBtn.setText(R.string.send);
		submitBtn.setVisibility(0);
		submitBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				new sendFeedbackTask().execute("");	
			}
		});
	}
	
	public class sendFeedbackTask extends AsyncTask<String, Integer, String>{

		@Override
		protected String doInBackground(String... params) {
			String result="";
			content = (EditText) findViewById(R.id.contentId);
			Map<String, String> map = new HashMap<String, String>();
			map.put("title", "Title");
			map.put("content", content.getText().toString());
			map.put("author", "Author");
			try {
				result = HttpUtil.postRequest(Constants.SERVER_URL + Constants.FEEDBACK_URI, map);
				// JSONObject json = new JSONObject(result);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return result;
		}

		/* (non-Javadoc)
		 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
		 */
		@Override
		protected void onPostExecute(String result) {
			finish();
			Toast.makeText(FeedbackActivity.this, "Thank you for your feedback", Toast.LENGTH_SHORT).show();						
		}
		
		
		
	}
	
	
	
	
	

}
